<template>
  <a-card>
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="myform" :model="model" :rules="validatorRules">
        <a-card title="基本设置" :bordered="false">
        <a-row style="width: 600px">
          <a-col :span="12">
            <a-form-model-item label="男用户需消耗" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="IntiConsumeGold">
              <a-input :min="0" style="width: 75%" v-model="model.IntiConsumeGold" placeholder="请输入"></a-input> 金币
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="可增加" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="IntiAddIntimacy">
              <a-input :min="0" style="width: 60%" v-model="model.IntiAddIntimacy" placeholder="请输入"  ></a-input> 亲密度
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="亲密度>=" :labelCol="newlabelCol" :wrapperCol="newwrapperCol" prop="IntiPass">
              <a-input :min="0" style="width: 60%" v-model="model.IntiPass" placeholder="请输入"  ></a-input> 解锁通话功能
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成为密友需双方亲密度>=" :labelCol="newlabelCol" :wrapperCol="newwrapperCol" prop="IntiEdsel">
              <a-input :min="0" v-model="model.IntiEdsel" placeholder="请输入"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col :span="24">
            <a-form-model-item v-bind="formItemLayoutWithOutLabel">
              <a-button type="primary" style="width: 150px;" @click="submitForm">确认修改</a-button>
            </a-form-model-item>
          </a-col>
        </a-row>
        </a-card>
        <a-card title="群发密友设置" :bordered="false">
          <a-row style="width: 600px">
            <a-col :span="24">
              <a-form-model-item label="群发密友一次至多可选" :labelCol="newlabelCol" :wrapperCol="newwrapperCol" prop="GroupMyd">
                <a-input :min="0" :precision="0" style="width: 60%" v-model="model.GroupMyd" placeholder="请输入"  ></a-input> 人
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="24">
              <a-form-model-item v-bind="formItemLayoutWithOutLabel">
                <a-button type="primary" style="width: 150px;" @click="submitForm">确认修改</a-button>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-card>


      </a-form-model>
    </a-spin>
  </a-card>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'IntimacySetting',
  components: {},
  data () {
    return {
      model:{
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      newlabelCol: {
        xs: { span: 24 },
        sm: { span: 8 },
      },
      newwrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      formItemLayoutWithOutLabel: {
        wrapperCol: {
          xs: { span: 24, offset: 0 },
          sm: { span: 20, offset: 2 },
        },
      },
      confirmLoading: false,
      validatorRules: {
        IntiConsumeGold: [
          { required: true, message: '请输入',name:'男用户需消耗多少金币'},
        ],
        IntiAddIntimacy: [
          { required: true, message: '请输入',name:'可增加多少亲密度'},
        ],
        IntiPass: [
          { required: true, message: '请输入',name:'亲密度>=多少解锁通话功能'},
        ],
        IntiEdsel: [
          { required: true, message: '请输入',name:'成为密友需双方亲密度>=多少'},
        ],
        GroupMyd:[
          { required: true, message: '请输入',name:'一次性群发密友多少人'},
        ],
      },
    }
  },
  created() {
    this.getSystemConfigMap();
  },
  methods: {
    //获取回显数据
    getSystemConfigMap(){
      getAction('/system/systemConfig/getSystemConfigMap').then((res)=>{
        if(res.success){
          this.model=res.result;
        }
      })
    },
    //保存数据
    submitForm () {
      const that = this;
      // 触发表单验证
      this.$refs.myform.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '/system/systemConfig/saveOrUpdate';
          let method = 'post';
          let dataList=[];
          //格式化数据
          for(let key in this.model){
            let obj={};
            obj.code=key;
            obj.value=this.model[key];
            if(that.validatorRules[key]){
              obj.title=that.validatorRules[key][0].name;
              dataList.push(obj)
            }
          }
          httpAction(httpurl,dataList,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  },
}
</script>

<style scoped>

</style>